﻿using Microsoft.WindowsAPICodePack.Shell;
using System.Windows.Forms;

namespace SkyJukebox
{
    public partial class SplashScreen : GlassForm
    {
        delegate void ProgressDelegate(string msg);
        delegate void SplashShowCloseDelegate();

        public SplashScreen()
        {
            InitializeComponent();
        }

        public void ShowSplashScreen()
        {
            if (InvokeRequired)
            {
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new SplashShowCloseDelegate(ShowSplashScreen));
                return;
            }
            Show();
            Application.Run(this);
        }

        public void CloseSplashScreen()
        {
            if (InvokeRequired)
            {
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new SplashShowCloseDelegate(CloseSplashScreen));
                return;
            }
            _closeSplashScreenFlag = true;
            Close();
        }

        public void ShowMessage(string msg)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new ProgressDelegate(ShowMessage), new object[] { msg });
                return;
            }
            label1.Text = msg;
        }

        private void SplashScreen_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_closeSplashScreenFlag == false)
                e.Cancel = true;
        }
    }
}
